#pragma once

#include "predef.h"

namespace LuabindSTL
{
	namespace Vector
	{
		template<typename T>
		const T::_Ty& At(T* self,T::size_type index)
		{
			return self->at(index)
		}

		template<typename T>
		void Add(T* self,const T::_Ty& val)
		{
			self->push_back(val);
		}

		template<typename T>
		void Insert(T* self,T::size_type index,const T::_Ty& val)
		{
			self->insert(self->begin()+index,val);
		}

		template<typename T>
		T::size_type Count(T* self)
		{
			return self->size();
		}

		template<typename T>
		void Remove(T* self,const T::_Ty& val)
		{
			self->erase(find(self->begin(),self->end(),val));
		}

		template<typename T>
		void RemoveAt(T* self,T::size_type index)
		{
			self->erase(self->begin()+index);
		}

		template<typename T>
		bool Contains(T* self,const T::_Ty& val)
		{
			return find(self->begin(),self->end(),val)==self->end();
		}

		template<typename T>
		bool Empty(T* self)
		{
			return self->empty();
		}

		template<typename T>
		void Reverse(T* self)
		{
			self->reverse(self->begin(),self->end());
		}

		template<typename T>
		void Clear(T* self)
		{
			self->clear();
		}

		template<typename vectorType>
		void Bind(lua_State* l,const char* name,const char* moduleName=0)
		{

#if _DEBUG
			static bool alreadyBinded = false;
			assert(alreadyBinded==false);
			alreadyBinded=true;
#endif

			using namespace luabind;

			module(l,moduleName)
				[
					class_<vectorType>(name)
					.def(constructor<>())
					.def(constructor<vectorType::size_type>())
					.def(constructor<const vectorType&>())
					.property("Count",&Count<vectorType>)
					.property("Empty",&Empty<vectorType>)
					.def("Add",&Add<vectorType>)
					.def("At",&At<vectorType>)
					.def("Remove",&Remove<vectorType>)
					.def("RemoveAt",&RemoveAt<vectorType>)
					.def("Insert",&Insert<vectorType>)
					.def("Clear",&Clear<vectorType>)
					.def("Reverse",&Reverse<vectorType>)
					.def("Contains",&Contains<vectorType>)
				]
		}
	};
};
